﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SEGIService.Service.Basic.Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SEGIService.DataSync
{
    public class SigeCommunitySyncTask : SEGIIScheduledTask
    {
        private readonly IServiceScopeFactory _scopeFactory;
        private readonly ILogger<SigeCommunitySyncTask> _logger;

        public SigeCommunitySyncTask(IServiceScopeFactory scopeFactory, ILogger<SigeCommunitySyncTask> logger)
        {
            _scopeFactory = scopeFactory;
            _logger = logger;
        }

        public string Schedule => "*/1 * * * *";

        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            
            _logger.LogInformation("开始执行四格社区同步任务");
            Console.WriteLine("开始执行四格社区同步任务");
            using var scope = _scopeFactory.CreateScope();
            var syncService = scope.ServiceProvider.GetRequiredService<SigeCommunitySyncService>();

            await syncService.SyncCommunityDataAsync(cancellationToken);

            _logger.LogInformation("四格社区同步任务执行完成");
        }
    }


}
